home *** CD-ROM | disk | FTP | other *** search
- package com.extensibility.app;
-
- import javax.swing.undo.CompoundEdit;
- import javax.swing.undo.UndoManager;
- import javax.swing.undo.UndoableEdit;
-
- public class BaseUndoManager extends UndoManager {
- UndoAction undoAction = new UndoAction(this, "edit.item.undo", 90);
- RedoAction redoAction;
- UndoableEdit milestone;
- boolean milestoneBlocksUndo = false;
-
- public BaseUndoManager() {
- this.undoAction.setEnabled(false);
- this.redoAction = new RedoAction(this, "edit.item.redo", 68);
- this.redoAction.setEnabled(false);
- }
-
- public boolean addEdit(UndoableEdit var1) {
- boolean var2 = super.addEdit(var1);
- if (var2) {
- this.undoAction.updateUndoState();
- this.redoAction.updateRedoState();
- }
-
- return var2;
- }
-
- public void discardAllEdits() {
- super.discardAllEdits();
- this.undoAction.setEnabled(false);
- this.redoAction.setEnabled(false);
- }
-
- public BaseAction getUndoAction() {
- return this.undoAction;
- }
-
- public BaseAction getRedoAction() {
- return this.redoAction;
- }
-
- public void trimUndoneEdits() {
- UndoableEdit var1 = ((UndoManager)this).editToBeRedone();
- if (var1 != null) {
- ((UndoManager)this).trimEdits(super.edits.lastIndexOf(var1), super.edits.lastIndexOf(((CompoundEdit)this).lastEdit()));
- }
-
- this.redoAction.updateRedoState();
- }
-
- public void undo() {
- UndoableEdit var1 = ((UndoManager)this).editToBeUndone();
- if (var1 == this.milestone) {
- this.clearMilestone();
- }
-
- super.undo();
- }
-
- public boolean canUndo() {
- return this.milestone != null && this.milestoneBlocksUndo && this.milestone == ((UndoManager)this).editToBeUndone() ? false : super.canUndo();
- }
-
- public void setMilestone(boolean var1) {
- this.milestone = ((UndoManager)this).editToBeUndone();
- this.milestoneBlocksUndo = var1;
- if (var1) {
- this.undoAction.updateUndoState();
- }
-
- }
-
- public void clearMilestone() {
- this.milestone = null;
- if (this.milestoneBlocksUndo) {
- this.undoAction.updateUndoState();
- }
-
- this.milestoneBlocksUndo = false;
- }
-
- public void trimEditsSinceMilestone() {
- if (this.milestone != null) {
- int var1 = super.edits.lastIndexOf(this.milestone) + 1;
- int var2 = super.edits.lastIndexOf(((CompoundEdit)this).lastEdit());
- if (var1 <= var2) {
- ((UndoManager)this).trimEdits(var1, var2);
- }
- }
-
- }
-
- public void undoToMilestone() {
- if (this.milestone != null) {
- while(((UndoManager)this).editToBeUndone() != this.milestone) {
- this.undo();
- }
- }
-
- }
- }
-